package bluetoothCommunication;

import java.util.ArrayList;

public class MainTest {
	
	static Communicator comm =new Communicator();
	
	public static void main (String [] args){
				
		//testStuff();
	
//		testRotateSensorMotor();
//		testRotate();
//		testTravel();
//		testCheckBarcodeWithStop();
//		testCheckBarcode();
		
		testMultipleCommands();
//		testUltrasonic();
//		check360sensorRotation();
//		testTravel80();
//		testInfraRed();
//		testLightValues();
//		testInfraRedWhileTurning();
		
		

	}


	private static void testInfraRedWhileTurning() {
		while(true){
			System.out.println(comm.getDirectionIR());
			System.out.println(comm.getDirectionIR());
			System.out.println(comm.getDirectionIR());
			System.out.println(comm.getDirectionIR());
			comm.rotateSensorMotor(-20);
			System.out.println(comm.getDirectionIR());
			System.out.println(comm.getDirectionIR());
			System.out.println(comm.getDirectionIR());
			System.out.println(comm.getDirectionIR());
			comm.rotateSensorMotor(40);
			System.out.println(comm.getDirectionIR());
			System.out.println(comm.getDirectionIR());
			System.out.println(comm.getDirectionIR());
			System.out.println(comm.getDirectionIR());
			System.out.println(comm.getDirectionIR());
			comm.rotateSensorMotor(-20);


		}		
	}


	private static void testLightValues() {
		while(true){
			System.out.println(comm.getLightValue());
		}
	}


	private static void testInfraRed() {
		while(true){
			System.out.println(comm.getDirectionIR());
		}
	}


	private static void testTravel80() {
		comm.travel(40);
		comm.travel(40);
	}


	private static void testCheckBarcode() {
		comm.setSpeed(200);
		while(true){
			comm.travel(40);
			sleep(5000);
			comm.getBarcode();
		}
	}


	private static void check360sensorRotation() {
		
		for(int i=0;i<24;i++){
			comm.rotateSensorMotor(15);
			System.out.println(comm.getDistance());
		}
	}


	private static void testUltrasonic() {
//		while(true){
		comm.rotateSensorMotor(-90);
		System.out.println(comm.getDistance());
//		comm.travel(40);
		System.out.println(comm.getDistance());
		
		while(true){
			System.out.println(comm.getDistance());
		}
	}

	private static void testMultipleCommands() {
		testTravel();
		testRotate();
		testRotateSensorMotor();
		testRotate();
		testTravel();	

	}
	private static void sleep(int millis){
		try {
			Thread.sleep(millis);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	private static void testCheckBarcodeWithStop() {
		comm.setSpeed(200);
		comm.travel(40);	
		comm.terminate();
		comm.printValues();
//		ArrayList<Integer> values=comm.printValues();
//		for(int value: values){
//			System.out.println(bc.getColorFromValue(value));
//			String barcode = bc.Update(value);
//			if (!barcode.equals("")) {
//				System.out.println(barcode);
//			}
//		}
//		System.out.println("d");
		
//		while(true)
//			System.out.println("awesomef");
		//comm.getBarcode();
		
	}

	private static void testTravel() {
		System.out.println("Testing robot travel...");
		comm.travel(30);
		System.out.println("Testing robot travel COMPLETED");			
	}

	private static void testRotate() {
		System.out.println("Testing robot rotation...");
		comm.rotateRobot(-90);
		comm.rotateRobot(180);
		comm.rotateRobot(-180);
		comm.rotateRobot(180);

//		comm.rotateRobot();
		System.out.println("Testing robot rotation COMPLETED");
	}

	private static void testRotateSensorMotor() {
		System.out.println("Testing sensor rotation...");
		comm.rotateSensorMotor(-90);
		comm.rotateSensorMotor(180);
		comm.rotateSensorMotor(-90);
		comm.rotateSensorMotor(-90);
		comm.rotateSensorMotor(180);
		System.out.println("Testing sensor rotation COMPLETED");		
	}

	private static void testStuff() {
		comm.travel(40);
		while(true){
			comm.getBarcode();
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
			}
		}
		//test.terminate();
//		List<Integer> list= test.getList();
//		String result="";
//		for(int value: list){
//			result+=value;
//			result+=" ";
//		}
//		System.out.println(result);
//		//test.getBarcode();
		
	}
	
	
}
